package com.ruoyi.web.controller.basedata;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.datastatistics.domain.UserPrePayment;
import com.ruoyi.datastatistics.service.IUserPrePaymentService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 预存缴费记录Controller
 * 
 * @author gdqt
 * @date 2025-06-27
 */
@RestController
@RequestMapping("/basedata/payment")
public class UserPrePaymentController extends BaseController
{
    @Autowired
    private IUserPrePaymentService userPrePaymentService;

    /**
     * 查询预存缴费记录列表
     */
    @GetMapping("/list")
    public TableDataInfo list(UserPrePayment userPrePayment)
    {
        startPage();
        List<UserPrePayment> list = userPrePaymentService.selectUserPrePaymentList(userPrePayment);
        return getDataTable(list);
    }

    /**
     * 导出预存缴费记录列表
     */
    @Log(title = "预存缴费记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, UserPrePayment userPrePayment)
    {
        List<UserPrePayment> list = userPrePaymentService.selectUserPrePaymentList(userPrePayment);
        ExcelUtil<UserPrePayment> util = new ExcelUtil<UserPrePayment>(UserPrePayment.class);
        util.exportExcel(response, list, "预存缴费记录数据");
    }

    /**
     * 获取预存缴费记录详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(userPrePaymentService.selectUserPrePaymentById(id));
    }

    /**
     * 新增预存缴费记录
     */
    @Log(title = "预存缴费记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserPrePayment userPrePayment)
    {
        int v = userPrePaymentService.insertUserPrePayment(userPrePayment);
        return v>0 ? AjaxResult.success() : v == 0 ? AjaxResult.error("用户不存在/已离场！") : AjaxResult.error("非预存用户，缴费金额需大于欠费金额！");
    }

    /**
     * 修改预存缴费记录
     */
    @Log(title = "预存缴费记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UserPrePayment userPrePayment)
    {
        return toAjax(userPrePaymentService.updateUserPrePayment(userPrePayment));
    }

    /**
     * 删除预存缴费记录
     */
    @Log(title = "预存缴费记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(userPrePaymentService.deleteUserPrePaymentByIds(ids));
    }

    @GetMapping("/getPrePaymentList")
    public AjaxResult getPrePaymentList(String userId)
    {
        List<UserPrePayment> list = userPrePaymentService.getPrePaymentList(userId);
        return success(list);
    }

    /**
    * @Description: 今日收费汇总
    * @date: 2025/6/30 14:08
    * @author: zt
    */
    @GetMapping("/getPaySummaryToday")
    public AjaxResult getPaySummaryToday(String userId)
    {
        return success(userPrePaymentService.getPaySummaryToday(userId));
    }

    /**
    * @Description: 撤销预存
    * @date: 2025/7/2 13:58
    * @author: zt
    */
    @GetMapping("/revokedPrePayment")
    public AjaxResult revokedPrePayment(Long id){
        return success(userPrePaymentService.revokedPrePayment(id));
    } 
}
